﻿/******************************************************************************
* File description: animationController_Purify.h
* Function: 纯化动画Controller，基于State的状态，根据时间计算当前动画的过渡状态，并提供获取当前状态的接口
* Current Version: 1.0.0
* Author: JNN
* Date: 2025-07-01
*  -----
*  Copyright by 博坤生物 .
 *****************************************************************************/
#ifndef ANIMATIONCONTROLLER_PURIFY_H
#define ANIMATIONCONTROLLER_PURIFY_H

#include <QObject>
#include <QColor>
#include <QRgb>
#include <cmath>
#include <QTimer>
#include <QElapsedTimer>
#include <QQmlApplicationEngine>
#include "pipeGraph.h"
#include "animationState_Purify.h"
#include "syringeCalculator.h"

#include "animationCommObject_Purify.h"


class AnimationController_Purify : public QObject
{

    Q_OBJECT
public:
    AnimationController_Purify(AnimationState_Purify* state);
    ~AnimationController_Purify();

    void startTimer();                   //  2. 启动Timer
    void stopTimer();
    QVariantMap requestInfo();                        // [接口] 获取当前状态信息
    AnimationCommObject_Purify* requestInfo_object();

    void debugCommObject() { qDebug() << _commObject; }

    void crashStop();                   // 急停（貌似已弃用

public slots:
    void on_reset();
    void on_wheelChanged(int posi1, int posi2, double speed, int direct);
    void on_hatPressed();
    void on_hatPushed();
    void on_valveChanged(int idx, bool state1, bool state2);
    void on_syringeChanged(int idx, double percentage1, double percentage2, double speed);
    void on_liquidChanged(QMap<QString, QVector<int>> pathList);

    void updateState(double interval = -1);         // 状态计算更新z

private:

    QTimer*         _timer = nullptr;
    QElapsedTimer*  _timer_e = nullptr;     // 时间核算

    AnimationState_Purify* _state = nullptr;

    QVector<double>  _valveAngle;
    QVector<double>  _valveEnd;

    // 注射器
    QVector<double> _syringePercent;
    QVector<double> _syringePercentEnd;
    QVector<double> _syringePercentSpeed;
    QVector<int>    _syringeIsPushing;

    // 转盘
    double          _wheel;
    double          _wheelEnd;
    double          _wheelSpeed;
    double          _wheelDirect;

    // 瓶帽
    double          _hatPressPosi;
    int             _hatPressState;
    double          _hatPushPosi;
    int             _hatPushState;
    QVector<bool>   _bottleHasHat;

    bool            _refreshPosi = false;   // 在发送一个新的状态时，是否立即更新到旧的状态

    // 色谱柱粒子特效
    int             _particleNum = 6;
    QVector<double> _particle;
    QVector<double> _particle_speed = {1, 1.4, 1.8, 1.6, 1.2, 0.9};

    // 检测器特效
    double          _detectorAngle = 0;

    // 计时控制
    double          _interval = 40;     // 理论间隔
    double          _interval_real;     // 实际间隔
    double          _lastTime = 0;

    // 管道液体流动状态
    QMap<QString, stLiquidPath>  _pathList;

    AnimationCommObject_Purify*  _commObject;


};

#endif          // ANIMATIONCONTROLLER_PURIFY_H
